<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "mall_category".
 *
 * @property int $id
 * @property int $pid 上级分类表
 * @property int $sort 排序
 * @property string $name 分类名称
 * @property string $desc 描述
 * @property int $status 是否启用 1启用 -1禁用
 */
class MallCategory extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'mall_category';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['pid', 'sort', 'status'], 'integer'],
            [['name'], 'required'],
            [['name'], 'string', 'max' => 20],
            [['desc'], 'string', 'max' => 50],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'pid' => '上级',
            'sort' => '排序',
            'name' => '分类名',
            'desc' => '说明',
            'status' => '状态',
        ];
    }

    /**
     * 分类属性枚举
     * @return array
     */
    public static function attributeValue()
    {
        return [
            'status' => [
                '-1' => '禁用',
                '1' => '启用',
            ],
        ];
    }

    /**
     * 状态
     * @return string
     */
    public function getStatusValue()
    {
        switch ($this->status)
        {
            case -1:
                $value = '禁用';
                break;
            case 1:
                $value = '正常';
                break;
            default:
                $value = '空';
                break;
        }
        return $value;
    }
}
